package deliciouse.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import deliciouse.biz.CategoryBiz;
import deliciouse.biz.FoodBiz;
import deliciouse.biz.impl.CategoryBizImpl;
import deliciouse.biz.impl.FoodBizImpl;
import deliciouse.entity.Category;
import deliciouse.entity.Food;
@WebServlet("/foodlistmanege")
public class FoodListManegementServlet extends HttpServlet{
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		int id=0;
		int cid = 0;
		if(request.getParameter("cid")!=null&&!request.getParameter("cid").isEmpty()){
			cid=Integer.valueOf(request.getParameter("cid"));
		}
		id=cid;
		String title = null;
		if(request.getParameter("title")!=null&&!request.getParameter("title").isEmpty()){
			title=request.getParameter("title");
		}
		int pageNum= 1;
		int pageSize = 20;
/*		FoodDao foodDao = new FoodDaoImpl();
		CategoryDao categorydao =new CategoryDaoImpl();
		Category category = new Category();
		List<Category> categorylist = categorydao.getAll();
		List<Food> foodlist = foodDao.getAll();
		List<Food> foodsearchlist = foodDao.fetchByCondition(cid, title, pageNum, pageSize);*/
		FoodBiz foodbiz = new FoodBizImpl();
		CategoryBiz categorybiz = new CategoryBizImpl();
		Category category = new Category();
		List<Category> categorylist= categorybiz.getAll();
		List<Food> foodlist = foodbiz.getAll();
		List<Food> foodsearchlist = foodbiz.fetchByCondition(cid, title, pageNum, pageSize);
		//request.getSession().setAttribute("cid", cid);
		request.setAttribute("title", title);
		request.setAttribute("category", category);
		request.setAttribute("categorylist", categorylist);
		request.setAttribute("foodlist", foodlist);
		request.setAttribute("foodsearchlist", foodsearchlist);
		request.getRequestDispatcher("/admin/foodmanegement.jsp").forward(request, response);
	}
}
